
$(document).ready(function(){
    // render
    loadData();
    // event
    bindEventEdit();
});

function loadData() {
    var _maSDCoThe = ISS.SESSION.getSession('session_maSDCoThe');

    var measurement = {};
    measurement.maSDCoThe = _maSDCoThe;
    ISS.BACKEND.request({
        url: ISS.SESSION.getSession('contextPath') + '/service/admin/editMemberMeasurement',
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json'
        },
        type: 'POST',
        dataType: 'json',
        data: JSON.stringify(measurement),
        success: function (data) {
            var responseContent = data.responseObject;
            loadDataComplete(responseContent);
        }
    });
}

function loadDataComplete(measurement){
    ISS.DOM.setVal('#AdMemberMeasurement_code', measurement.maSDCoThe);
    ISS.DOM.setVal('#AdMemberMeasurement_breast', measurement.sdNguc);
    ISS.DOM.setVal('#AdMemberMeasurement_waist', measurement.sdEo);
    ISS.DOM.setVal('#AdMemberMeasurement_butt', measurement.sdMong);
    ISS.DOM.setVal('#AdMemberMeasurement_back', measurement.sdDaiLung);
    ISS.DOM.setVal('#AdMemberMeasurement_arm', measurement.sdDaiTay);
    ISS.DOM.setVal('#AdMemberMeasurement_shoulder', measurement.sdVai);
    ISS.DOM.setVal('#AdMemberMeasurement_height', measurement.sdChieuCao);
    ISS.DOM.setVal('#AdMemberMeasurement_weight', measurement.sdCanNang);
}

function bindEventEdit(){
    ISS.EVENT.bindEvent('#AdMemberMeasurement_Modified', 'click', function () {
        sendInfoEdit();
    });
}

function sendInfoEdit() {
    var measurement = {};

    measurement.maSDCoThe = ISS.DOM.getVal('#AdMemberMeasurement_code');
    measurement.sdNguc = ISS.DOM.getVal('#AdMemberMeasurement_breast');
    measurement.sdEo = ISS.DOM.getVal('#AdMemberMeasurement_waist');
    measurement.sdMong = ISS.DOM.getVal('#AdMemberMeasurement_butt');
    measurement.sdDaiLung = ISS.DOM.getVal('#AdMemberMeasurement_back');
    measurement.sdDaiTay = ISS.DOM.getVal('#AdMemberMeasurement_arm');
    measurement.sdVai = ISS.DOM.getVal('#AdMemberMeasurement_shoulder');
    measurement.sdChieuCao = ISS.DOM.getVal('#AdMemberMeasurement_height');
    measurement.sdCanNang = ISS.DOM.getVal('#AdMemberMeasurement_weight');

    ISS.BACKEND.request({
        url: ISS.SESSION.getSession('contextPath') + '/service/admin/registerMemberMeasurementEdit',
        headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json'
        },
        type: 'POST',
        dataType: 'json',
        data: JSON.stringify(measurement),
        success: function (data) {
            var responseContent = data.responseObject;
            sendInfoEditComplete(responseContent);
        }
    });
}

function sendInfoEditComplete(measurement) {
    if(measurement) {
        ISS.WINDOW.location('/jsp/admin/ad-member-measurement-common.jsp');
    }
    else{
        alert('Cập nhật không thành công');
    }
}
